<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>v-for指令</title>
</head>

<body>
    <div id="app">
        <ul>
            <li v-for="item in arr">
                学习程序的校区:{{item}}
            </li>
        </ul>
        <input type="button" value="增加一个蔬菜" @click="add">
        <input type="button" value="减少一个蔬菜" @click="remove">
        <h2 v-for="item in vegetables">{{item.name}}</h2>
    </div>

    <!-- 开发环境版本 -->
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script>
        var app = new Vue({
            el: "#app",
            data: {
                arr: ["北京", "上海", "广州", "深圳"],
                vegetables: [
                    { name: "西蓝花炒鸡蛋" },
                    { name: "鸡蛋炒西蓝花" }
                ]
            },
            methods: {
                add: function () {
                    this.vegetables.push({ name: "番茄炒鸡蛋" })
                },
                remove: function () {
                    this.vegetables.shift();
                }
            }
        })
    </script>
</body>

</html>